%option noyywrap nodefault case-insensitive
%{
#ifndef _YACC_TAB_HEADER_
#define _YACC_TAB_HEADER_
#include "../include/y.tab.h"
#endif
#ifndef _DATABASE_OPERATION_HEADER_
#define _DATABASE_OPERATION_HEADER_
#include "../include/operation.h"
#endif
%}

%%

create {

        return CREATE;}
select {
printf("select\n");
return SELECT;}
insert {printf("insert\n");return INSERT;}
update {printf("update\n");return UPDATE;}
delete {printf("delete\n");return DELETE;}
show {printf("show\n"); return SHOW;}
desc {printf("desc\n"); return DESC;}
databases {printf("databases\n");return DATABASES;}
database {printf("database\n");return DATABASE;}
tables {return TABLES;}
table {printf("table\n");return TABLE;}
into {printf("into\n");return INTO;}
values {printf("values\n");return VALUES;}
where {printf("where\n");return WHERE;}
set {printf("get set\n");return SET;}
primary {return PRIMARY;}
foreign {return FOREIGN;}
as {return AS;}
use {return USE;}
key {return KEY;}


drop {return DROP;}
and {printf("and\n");return AND;}
or {printf("or\n");return OR;}

not {printf("not\n");return NOT;} //  认为与！等价

from {return FROM;}
is {printf("is\n");return IS;}
help  {return HELP;}
exit {return EXIT;}
null {printf("nul");return NUL;}
char {return CHAR;}
int {printf("\tint\n");return INT;}
double {return DOUBLE;}
auto_increment {return AUTOINCREMENT;}

!= {yylval.cp = NE; printf("!=\n");return CP;}
> {yylval.cp = GT;  printf(">\n"); return CP;}
\< {yylval.cp = LT; printf("<\n"); return CP;}
>= {yylval.cp = GE; printf(">=\n"); return CP;}
\<= {yylval.cp = LE;printf("<=\n"); return CP;}
== {yylval.cp = EQ; printf("==\n"); return CP;}
! {printf("!\n"); return NOT;}


[+\-]?[1-9][0-9]*|0 {
    yylval.m_data = (struct Data *)malloc(sizeof(struct Data));
    yylval.m_data->value.i = atoi(yytext);
    yylval.m_data->type=  FIELD_INT;
    printf("%d|\tas number!\n",atoi(yytext));
    return DATA_INT;
    }
[+\-]?(([1-9][0-9]*)|0)"."[0-9]+  {
    yylval.m_data = (struct Data *)malloc(sizeof(struct Data));
    yylval.m_data->value.d = atof(yytext);
    printf("%lf| as double!\n",atof(yytext));
    yylval.m_data->type=  FIELD_DOUBLE;
    return DATA_DOUBLE;
    }
`.*` {
    yylval.m_data = (struct Data *)malloc(sizeof(struct Data));
    yytext = yytext+1;
    yylval.m_data->value.m_string = (char *)malloc(sizeof(char) * strlen(yytext));
    strcpy( yylval.m_data->value.m_string,yytext);
    yylval.m_data->value.m_string[strlen(yytext)-1] = '\0';
    yylval.m_data->type = FIELD_STRING;
    printf("read string %s",yytext);
    return DATA_STRING;
    }


[a-zA-Z][a-zA-Z0-9_]+    {
yylval.m_string = (char*)malloc(strlen(yytext));
strcpy(yylval.m_string,yytext) ;
printf("%s|\tas Identify!\n",yytext); return ID;}

[0-9][a-zA-Z0-9_]+  {printf("error:'%s' is not a symbol!\n",yytext);}

; {printf("delimeter\n");return DELIMETER;}

"#".*

\n {printf("\nLiSQL> ");}

[ \t] {}

\* {printf("*\n");return yytext[0];}
\( {printf("\(\n");return yytext[0];}
\) {printf("\)\n");return yytext[0];}
\[ {printf("\[\n");return yytext[0];}
\] {printf("\]\n");return yytext[0];}
\{ {printf("\{\n");return yytext[0];}
\} {printf("\}\n");return yytext[0];}
, {printf("\(\n");return yytext[0];}
= {printf("=\n");return yytext[0];}

. {printf("\(\n");printf("%s\n",yytext);}



%%